package com.me.beanLife;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

public class TestBeanLifeCycle {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        context.getBean("userInfoBean");
        // 关闭容器，触发 bean 的销毁方法
        context.close();
    }

    @Configuration
    @PropertySource("classpath:common.conf")
    public static class AppConfig {

        @Bean
        public MyInstantiationAwareBeanPostProcessor instantiationAwareBeanPostProcessor() {
            return new MyInstantiationAwareBeanPostProcessor();
        }

        @Bean(initMethod = "initMethod", destroyMethod = "destroyMethod")
        public UserInfoBean userInfoBean() {
            return new UserInfoBean();
        }

        @Bean
        public MyBeanPostProcessor beanPostProcessor() {
            return new MyBeanPostProcessor();
        }

        @Bean
        public MyBeanFactoryPostProcessor beanFactoryPostProcessor() {
            return new MyBeanFactoryPostProcessor();
        }

    }
}
